
"""
43.字符串相乘
https://leetcode.cn/problems/multiply-strings/
"""


class Solution:

    def method1(self, num1: str, num2: str) -> str:
        """
        投机取巧：转化为数字相乘
        适应性不强，只是因为python支持大数运算
        """
        # 两种方式
        res = int(num1) * int(num2)
        # res = eval(f"{num1} * {num2}")
        return str(res)

    def method2(self, num1: str, num2: str) -> str:
        """
        就是逐位相带上进制数
        """
        if len(num1)>len(num2):
            num1, num2 = num2, num1  # num1为较小的数字

        res = 0
        for i1, v1 in enumerate(num1[::-1]):
            for i2, v2 in enumerate(num2[::-1]):
                res += int(v1)*10**i1 * int(v2)*10**i2
        return str(res)

    def multiply(self, num1: str, num2: str) -> str:
        return self.method2(num1, num2)


def test():
    obj = Solution()
    res = obj.multiply('123', '456')
    print(res)


if __name__ == "__main__":
    test()
